package com.xnchat.pro.dataStructure;

import java.io.Serializable;

/**
 * @author woziji
 */
public class MyStack<T> {
    private int point = 0;//定义指针
    private T[] localArray;
    private int initializationSize;

    public MyStack(int initializationSize) {
        localArray = (T[]) new Object[initializationSize];
        this.initializationSize = initializationSize;
    }

    //peek
    public T peek() {
        return localArray[point];
    }

    //pop
    public T pop() {
        if (point > 0) {
            return localArray[point--];
        }
        return null;
    }

    //push
    public T push(T t) {
        if (point + 1 >= initializationSize) {
            return null;
        }
        localArray[++point] = t;
        return t;
    }

}
